package com.yumeng.example.main.controller;

import com.yumeng.common.api.ApiResult;
import com.yumeng.common.runtime.SpringPropAdapter;
import com.yumeng.config.properties.YumengProperties;
import com.yumeng.config.helper.EnvHelper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wxd
 * @date 2024/5/28 下午1:43
 */
@Slf4j
@RestController
//@ApiSupport(order = 2)
@Tag(name = "环境Controller", description = "环境接口集合")
@RequestMapping("/example/env")
public class ExampleEnvController {

    @Autowired
    private YumengProperties ymProperties;

    @Operation(summary = "获取Spring上下文")
    @GetMapping("/testContext.do")
    public ApiResult testContext(){
        Map<String, Object> map = new HashMap<>();
        map.put("applicationId", SpringPropAdapter.getApplicationId());
        map.put("applicationName", SpringPropAdapter.getApplicationName());
        map.put("activeProfiles", SpringPropAdapter.getActiveProfiles());
        map.put("defaultProfiles", SpringPropAdapter.getDefaultProfiles());
        map.put("isDev", EnvHelper.isDev());
        map.put("isTest", EnvHelper.isTest());
        map.put("isUat", EnvHelper.isUat());
        map.put("isProd", EnvHelper.isProd());

        map.put("配置文件", ymProperties.getLastCfgName());
        map.put("当前环境", ymProperties.getCurrEnvSysDesc());
        return ApiResult.successData(map);
    }

}
